//
//  FQProductDetailViewController.swift
//  SwiftProject
//
//  Created by 董駸 on 2023/4/14.
//

import UIKit

class FQProductDetailViewController: BaseViewController, ListAdapterDataSource {
    lazy var adapter : ListAdapter = {
        ListAdapter(updater: ListAdapterUpdater(), viewController: self)
    }()
    let collectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout())
    var dataArray : [BaseIGListKitModel] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        navigationBarType = .custom
    }
    
    override func initSubviews() {
        super.initSubviews()

        safeAreaBottomView.backgroundColor = .white
        
        let bottomView = UIView()
        bottomView.backgroundColor = .white
        view.addSubview(bottomView)
        
        bottomView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.bottom.equalTo(safeAreaBottomView.snp.top)
            make.height.equalTo(60)
        }
        
        let kefu = QMUIButton(title: "客服", titleColor: .color102, font: .rSFont(13))
        kefu.setImage(UIImage(named: "detail_kefu"), for: .normal)
        kefu.imagePosition = .top
        kefu.spacingBetweenImageAndTitle = 8
        kefu.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
        kefu.tag = 1
        bottomView.addSubview(kefu)
        
        kefu.snp.makeConstraints { make in
            make.left.equalTo(20)
            make.width.equalTo(50)
            make.centerY.equalToSuperview()
        }
        
        let sendBtn = QMUIFillButton(fill: .colorMain, titleTextColor: .white)
        sendBtn.setTitle("立即申请", for: .normal)
        sendBtn.titleLabel?.font = .mSFont(19)
        sendBtn.addTarget(self, action: #selector(buttonClick(_:)), for: .touchUpInside)
        sendBtn.tag = 2
        bottomView.addSubview(sendBtn)
        
        sendBtn.snp.makeConstraints { make in
            make.right.equalTo(-20)
            make.left.equalTo(kefu.snp.right).offset(10)
            make.height.equalTo(50)
            make.centerY.equalToSuperview()
        }
        
        dataArray = [FQDetailHeaderModel(), FQDetailListModel()]
        
        collectionView.backgroundColor = view.backgroundColor
        collectionView.contentInsetAdjustmentBehavior = .never
        view.addSubview(collectionView)
        adapter.collectionView = collectionView
        adapter.dataSource = self
//        adapter.scrollViewDelegate = self

        collectionView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalToSuperview()
            make.bottom.equalTo(bottomView.snp.top)
        }
    }
    
    func objects(for listAdapter: ListAdapter) -> [ListDiffable] {
        dataArray
    }

    func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController {
        switch object {
        case is FQDetailHeaderModel:
            return FQDetailHeaderSectionController()
        default:
            return FQDetailListSectionController()
        }
    }

    func emptyView(for listAdapter: ListAdapter) -> UIView? {
        return nil
    }

    @objc func buttonClick(_ button : QMUIButton) {
        
    }
    
    override func setupNavigationItems() {
        super.setupNavigationItems()
        title = "XX产品"
    }
    
    override func qmui_navigationBarBackgroundImage() -> UIImage? {
        .qmui_image(with: .colorMake(60, 88, 162), size: CGSize(width: SCREEN_WIDTH, height: NavigationContentTop), cornerRadius: 0)
    }

    override func customNavigationBarTransitionKey() -> String? {
        "detail"
    }
}
